package com.zytool.easyrestful.core.bean;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
@ApiModel("统一返回结构")
public class ResultBean<T> {

    @ApiModelProperty("编码")
    private int code;
    @ApiModelProperty("消息")
    private String message;
    @ApiModelProperty("数据")
    private T data;

    public ResultBean() {
    }

    public ResultBean(T data) {
        this.data = data;
    }

    public ResultBean(ResultStatus cm) {
        this.code = cm.getCode();
        this.message = cm.getMessage();
    }

    public static <T> ResultBean<T> success(T data) {
        return new ResultBean<T>(data);
    }

    public static <T> ResultBean<T> error(ResultStatus cm) {
        return new ResultBean<T>(cm);
    }
}